package com.arthur.gao.springbootwebsocket.socketjs.controller;

import com.arthur.gao.springbootwebsocket.socketjs.RequestMessage;
import com.arthur.gao.springbootwebsocket.socketjs.ResponseMessage;
import org.springframework.messaging.handler.annotation.MessageMapping;
import org.springframework.messaging.handler.annotation.SendTo;
import org.springframework.stereotype.Controller;

/**
 * Created by gaopan on 2019-04-22 15:04
 */
@Controller
public class WsController {

    /**
     * @MessageMapping 注解和我们之前使用的@RequestMapping类似。
     * @SendTo 注解表示当服务器有消息需要推送的时候，会对订阅了@SendTo中路径的浏览器发送消息。
     * @param message
     * @return
     */
    @MessageMapping("/welcome")
    @SendTo("/topic/getResponse")
    public ResponseMessage say(RequestMessage message) {
        System.out.println(message.getName());
        return new ResponseMessage("welcome," + message.getName() + " !");
    }
}
